<template>
  <div class="check-container">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>设备检测</span>
        </div>
      </template>
      <div class="content">
        <p>正在检测设备类型...</p>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';

const route = useRoute();
const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

onMounted(() => {
  // 检测是否为iOS设备
  const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !(window as any).MSStream;

  // 获取原始URL
  const rtmpUrl = route.query.rtmpUrl as string;
  if (!rtmpUrl) {
    console.error('未提供视频地址');
    return;
  }

  // 根据设备类型跳转到不同的播放页面
  if (isIOS) {
    // iOS设备使用m3u8播放器
    const m3u8Url = rtmpUrl.replace('rtmp://', 'http://').replace(/\?/, '.m3u8?').replace(/&/g, '%26');
    const encodedUrl = encodeURIComponent(m3u8Url);
    router.replace(`/video/playM3u8?rtmpUrl=${encodedUrl}`);
  } else {
    // 其他设备使用flv播放器
    const flvUrl = rtmpUrl.replace('rtmp://', 'http://').replace(/\?/, '.flv?').replace(/&/g, '%26');
    const encodedUrl = encodeURIComponent(flvUrl);
    router.replace(`/video/play?rtmpUrl=${encodedUrl}`);
  }
});
</script>

<style scoped>
.check-container {
  padding: 20px;
}

.content {
  text-align: center;
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
